repo: Check for OSTREE_REPO in ostree_repo_new_default()
authorMatthew Barnes <mbarnes@redhat.com>
Thu, 19 Feb 2015 15:30:25 +0000 (10:30 -0500)
committerMatthew Barnes <mbarnes@redhat.com>
Fri, 20 Feb 2015 01:44:34 +0000 (20:44 -0500)
Convenience feature to avoid having to pass --repo options repeatedly.

Before falling back to the default system repository path, check for a
repository path defined by the OSTREE_REPO environment variable.

doc/ostree.repo.xml
src/libostree/ostree-repo.c

index eb9e3292a01f9b0322771cc3007e02f09199a4e9..b8ad4052989f16a4b3ecb5c7693cb400e9aa2559 100644 (file)
                <para>
                  There is a system repository located at
                  <filename>/ostree/repo</filename>.  If no repository
-                 is specified, the <command>ostree</command> as well
-                 as many API calls will use it by default.
+                 is specified -- either by a command-line option or the
+                 <envar>OSTREE_REPO</envar> environment variable --
+                 the <command>ostree</command> as well as many API
+                 calls will use it by default.
                </para>
         </refsect1>
 
index 85792d880e719b3f7464d3124795687d8057a207..62fff9edd2d82c1485fa727be7a7828ed5a9603f 100644 (file)
@@ -511,7 +511,8 @@ get_default_repo_path (void)
  *
  * If the current working directory appears to be an OSTree
  * repository, create a new #OstreeRepo object for accessing it.
- * Otherwise, use the default system repository located at
+ * Otherwise use the path in the OSTREE_REPO environment variable
+ * (if defined) or else the default system repository located at
  * /ostree/repo.
  *
  * Returns: (transfer full): An accessor object for an OSTree repository located at /ostree/repo
@@ -527,8 +528,15 @@ ostree_repo_new_default (void)
     }
   else
     {
-      gs_unref_object GFile *default_repo_path = get_default_repo_path ();
-      return ostree_repo_new (default_repo_path);
+      const char *envvar = g_getenv ("OSTREE_REPO");
+      gs_unref_object GFile *repo_path = NULL;
+
+      if (envvar == NULL || *envvar == '\0')
+        repo_path = get_default_repo_path ();
+      else
+        repo_path = g_file_new_for_path (envvar);
+
+      return ostree_repo_new (repo_path);
     }
 }